package cn.edu.java.thread.原子类;

import java.util.concurrent.atomic.AtomicMarkableReference;

public class AtomicMarkableReferenceDemo {
    private static AtomicMarkableReference<String> reference = new AtomicMarkableReference<>("initial", false);

    public static void main(String[] args) {
        // 获取当前引用和标记值
        boolean[] markHolder = new boolean[1];
        String currentReference = reference.get(markHolder);
        boolean currentMark = markHolder[0];
        System.out.println("Current reference: " + currentReference);
        System.out.println("Current mark: " + currentMark);

        // 尝试更新引用和标记值
        boolean success = reference.compareAndSet("initial", "new", false, true);
        System.out.println("Compare and set result: " + success);

        // 获取更新后的引用和标记值
        currentReference = reference.get(markHolder);
        currentMark = markHolder[0];
        System.out.println("Current reference: " + currentReference);
        System.out.println("Current mark: " + currentMark);
    }
}
